package net.fdukedom.epicurus.domain.entity;

/**
 * Page entity.
 *
 * @author Sergey Vishnyakov
 */
public final class Page {

    /**
     * Id.
     */
    private int id;

    /**
     * Page name.
     */
    private String  name;

    /**
     * Page location.
     */
    private String location;

    /**
     * Related plugin.
     */
    private Plugin plugin;

    /**
     * Default constructor.
     */
    public Page() {
    }

    /**
     * Creates instance out of name, location and plugin.
     *
     * @param name page name
     * @param location page location
     * @param plugin plug-in that owns the page
     */
    public Page(String name, String location, Plugin plugin) {
        this.name = name;
        this.location = location;
        setPlugin(plugin);
    }

    /**
     * Returns id.
     *
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * Sets id.
     *
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Returns location.
     *
     * @return the location
     */
    public String getLocation() {
        return location;
    }

    /**
     * Sets location.
     *
     * @param location the location to set
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * Returns name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets name.
     *
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * Returns plugin.
     *
     * @return the plugin
     */
    public Plugin getPlugin() {
        return plugin;
    }

    /**
     * Sets plugin.
     *
     * @param plugin the plugin to set
     */
    public void setPlugin(Plugin plugin) {
        this.plugin = plugin;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final Page page = (Page) o;

        if (name != null ? !name.equals(page.name) : page.name != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (name != null ? name.hashCode() : 0);
        result = 29 * result + (location != null ? location.hashCode() : 0);
        return result;
    }

    public String toString() {
        StringBuilder text = new StringBuilder();
        text.append("{id: ");
        text.append(id);
        text.append(", name: ");
        text.append(name);
        text.append(", location: ");
        text.append(location);
        text.append(", plugin name: ");
        text.append(plugin.getName());
        text.append("}");
        return text.toString();
    }
}

